package com.ruoyi.web.controller.resource;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.resource.domain.SysBusinessResourceModel;
import com.ruoyi.resource.service.ISysBusinessResourceModelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型资源Controller
 *
 * @author ruoyi
 * @date 2023-12-22
 */
@RestController
@RequestMapping("/resource/model")
public class SysBusinessResourceModelController extends BaseController
{
    @Autowired
    private ISysBusinessResourceModelService sysBusinessResourceModelService;

    /**
     * 查询模型资源列表
     */
    @PreAuthorize("@ss.hasPermi('resource:model:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBusinessResourceModel sysBusinessResourceModel)
    {
        startPage();
        List<SysBusinessResourceModel> list = sysBusinessResourceModelService.selectSysBusinessResourceModelList(sysBusinessResourceModel);
        return getDataTable(list);
    }

    /**
     * 导出模型资源列表
     */
    @PreAuthorize("@ss.hasPermi('resource:model:export')")
    @Log(title = "模型资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBusinessResourceModel sysBusinessResourceModel)
    {
        List<SysBusinessResourceModel> list = sysBusinessResourceModelService.selectSysBusinessResourceModelList(sysBusinessResourceModel);
        ExcelUtil<SysBusinessResourceModel> util = new ExcelUtil<SysBusinessResourceModel>(SysBusinessResourceModel.class);
        util.exportExcel(response, list, "模型资源数据");
    }

    /**
     * 获取模型资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('resource:model:query')")
    @GetMapping(value = "/{modelId}")
    public AjaxResult getInfo(@PathVariable("modelId") Long modelId)
    {
        return success(sysBusinessResourceModelService.selectSysBusinessResourceModelByModelId(modelId));
    }

    /**
     * 新增模型资源
     */
    @PreAuthorize("@ss.hasPermi('resource:model:add')")
    @Log(title = "模型资源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBusinessResourceModel sysBusinessResourceModel)
    {
        return toAjax(sysBusinessResourceModelService.insertSysBusinessResourceModel(sysBusinessResourceModel));
    }

    /**
     * 修改模型资源
     */
    @PreAuthorize("@ss.hasPermi('resource:model:edit')")
    @Log(title = "模型资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBusinessResourceModel sysBusinessResourceModel)
    {
        return toAjax(sysBusinessResourceModelService.updateSysBusinessResourceModel(sysBusinessResourceModel));
    }

    /**
     * 删除模型资源
     */
    @PreAuthorize("@ss.hasPermi('resource:model:remove')")
    @Log(title = "模型资源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{modelIds}")
    public AjaxResult remove(@PathVariable Long[] modelIds)
    {
        return toAjax(sysBusinessResourceModelService.deleteSysBusinessResourceModelByModelIds(modelIds));
    }
}
